package com.example.myapplication.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class ElementAdapter extends RecyclerView.Adapter<ElementAdapter.ViewHolder> {

    private Elements list;
    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView hour;
        TextView weath;
        TextView temperature;

        public ViewHolder (View view) {
            super(view);
            hour = (TextView) view.findViewById(R.id.weath_date);
            weath = (TextView) view.findViewById(R.id.weath_detail);
            temperature = (TextView) view.findViewById(R.id.weath_temper);
        }

    }

    public ElementAdapter(Elements list){
        this.list = list;
    }

    @Override

    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.day15_item,parent,false);
        ViewHolder holder = new ViewHolder(view);
        ViewGroup.LayoutParams layoutParams = holder.itemView.getLayoutParams();
        layoutParams.width=Math.round(parent.getWidth()/3);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position){
        Element e = list.get(position);
        holder.hour.setText(e.select("p").first().text());
        holder.weath.setText(e.select("p").get(1).text());
        holder.temperature.setText(e.select("p").get(2).text());

    }

    @Override
    public int getItemCount(){
        return list.size();
    }

}
